package com.hzncc.flowable_diboot.job;

import com.diboot.scheduler.annotation.CollectThisJob;
import com.hzncc.flowable_diboot.service.SalesSignInService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.QuartzJobBean;

@DisallowConcurrentExecution
@CollectThisJob(
        name = "获取钉钉签到记录",
        cron = "0 0 * * * ? *"
)
public class CheckInNewJob extends QuartzJobBean implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        SalesSignInService bean = applicationContext.getBean(SalesSignInService.class);
        try {
            JobDataMap dataMap = context.getMergedJobDataMap();
            Object interval = dataMap.get("interval");
            bean.execute(Long.parseLong(interval.toString()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
